package DP;

import java.util.Scanner;

public class 背包问题一维 {
    static class Solution {
        public int backpack(int[] weight, int[] value, int bag) {
            int n = weight.length;
            int[] dp = new int[bag+1];
            for (int i = 0; i <= bag; i++) {
                if ( i>=weight[0] ) dp[i] = value[0];
            }
            for (int i = 1; i < n; i++) { // 物品
                for (int j = bag ; j >= weight[i]; j--) {  // 背包 这里关键，不能重复放物品，因此从大到小遍历
                        dp[j] = Math.max(dp[j], dp[j - weight[i]] + value[i]);
                }
            }
            return dp[bag];
        }
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();
        int bag = scanner.nextInt();
        int[] weight = new int[n];
        int[] value = new int[n];
        for (int i = 0; i < n; i++) {
            weight[i] = scanner.nextInt();
        }
        for (int i = 0; i < n; i++) {
            value[i] = scanner.nextInt();
        }

        int res = solution.backpack(weight, value, bag);
        System.out.println(res);
    }
}
